﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DualControl.Controllers;
using DualControl.EmergencyMeasures;
using DualControl.EmergencyMeasures.Dtos;
using DualControl.HazardSources;
using DualControl.HazardSources.Dtos;
using DualControl.RiskPoints.Dtos;
using Microsoft.AspNetCore.Mvc;
using X.PagedList;

namespace DualControl.Web.Mvc.Controllers
{
    public class EmergencyMeasuresController : DualControlControllerBase
    {
        private readonly IEmergencyMeasureAppService  _emergencyMeasureAppService;

        public EmergencyMeasuresController(IEmergencyMeasureAppService emergencyMeasureAppService)
        {
           _emergencyMeasureAppService =emergencyMeasureAppService;
        }      

        public async Task<ActionResult> Index(int page)
        {

            int pagenumber = page < 1 ? 1 : page;
            GetEmergencyMeasuresInput input = new GetEmergencyMeasuresInput
            {
                SkipCount = (pagenumber - 1) * AppConsts.DefaultPageSize,
                MaxResultCount = AppConsts.DefaultPageSize
            };
            var result = await _emergencyMeasureAppService.GetPagedHSEmergencyMeasure(input);
            var PageOfHSEmergencyMeasureListDto = new StaticPagedList<HSEmergencyMeasureListDto>(result.Items, pagenumber, AppConsts.DefaultPageSize, result.TotalCount);
            //将分页结果放入ViewBag供View使用
            ViewBag.PageOfHSEmergencyMeasureListDto = PageOfHSEmergencyMeasureListDto;

            return View();
        }

    }
}